import { _decorator, Component, EventTouch, Node } from 'cc';
import { ModuleBase } from './ModuleBase';
const { ccclass, property } = _decorator;

@ccclass('TouchLayer')
export class TouchLayer extends ModuleBase {

    private _isClick: boolean = false;

    onInit(...rest: any[]): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchStart, this);
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
    }

    // changeClickState(isClick: boolean) {
    //     this._isClick = isClick;
    // }

    //创建玩家
    onTouchStart(event: EventTouch) {
        this.sendMsg("onTouchStart", "PlayerLayers", event);
        console.log("鼠标点击");
    }

    onTouchEnd(event: EventTouch) {
        this.sendMsg("onTouchEnd", "PlayerLayers", event);
        console.log("鼠标抬起");
    }

    protected onDestroy(): void {
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
        this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchEnd, this);
    }

}


